package com.bn.util;

import atg.nucleus.GenericService;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class ValidationManager extends GenericService{
	private static final String REGX_US_POSTAL_CODE = "^[-+]?[0-9]*\\.?[0-9]+$";
	private static final String PHONE_NUMBER = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$";

	public ValidationManager(){
		super();
	}

	/**
	 * Check the postal code is valid.
	 *
	 * @param postalcode
	 * @return
	 */
	public boolean validpostalCode(String postalcode) {

		boolean isValid = true;
		String expression = REGX_US_POSTAL_CODE;
		Pattern pattern = Pattern.compile(expression);
		Matcher matcher = pattern.matcher(postalcode);
		if (!matcher.matches()) {
			isValid = false;
		}
		return isValid;
	}

	/**
	 * Check the phone number is valied
	 *
	 * @param number
	 * @return
	 */
	public boolean isvalidPhonenumber(String number) {

		boolean isValid = true;

		String expression = PHONE_NUMBER;

		Pattern pattern = Pattern.compile(expression);
		Matcher matcher = pattern.matcher(number);
		if (!matcher.matches()) {
			isValid = false;
		}
		return isValid;
	}
}
